package cn.bigfire.wzdj.util.sign;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.HMac;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
@Slf4j
public class Param {

    public static int appId = 2074;
    public static int pid = 2074010;
    public static int clientType = 5;
    public static int encryptflag = 0;
    public static String uuid = "wx-ol9sW7RiscrRqWOQ1wPrQSP0NKEM";
    public static int timestamp = getTimestamp();
    public static String version = "v2";
    public static int subUserType = 1051;

    public static String key = "d01474ee9670540687a7f2464a570abc";
    public static String m() {
        String param = "appid=" + appId + "&body=" + body() + "&clienttype=" + clientType + "&encryptflag=" + encryptflag + "&pid=" + pid + "&returntype=2&timestamp=" + timestamp + "&uuid=" + uuid + "&version=" + version + "&version=" + subUserType;
        HMac hMac = SecureUtil.hmacSha256(key);
        return hMac.digestHex(param);
    }




    public static int getTimestamp() {
        String timeStr = String.valueOf(System.currentTimeMillis()).substring(0, 10);
        return Integer.parseInt(timeStr);
    }

    public static String getUrl() {
        String tlp = "https://sdkapi.hnys68.cn/api/sdk/v2/accounts/action/registerlogin/openuser-mp?appId=2074&pid=2074010&clientType=5&encryptflag=0&uuid=wx-ol9sW7RiscrRqWOQ1wPrQSP0NKEM&timestamp=%s&version=v2&subUserType=1051&sign=%s";
        String url = String.format(tlp, timestamp, m());
        return url;
    }

    public static String body() {
        return "{\"openAppId\":\"wx71702c33334e92bd\",\"userType\":105,\"token\":\"0c1xSZkl22Sjpe4d0nol2dU9Jp4xSZkL\",\"formAdID\":\"\",\"fromRSID\":\"\",\"adInfo\":\"{\\\"pid\\\":2074010}\",\"adCache\":\"\"}";
    }


    public static HashMap<String,String> headers(){
        HashMap<String,String> headers = new HashMap<>();
        headers.put("Host","sdkapi.hnys68.cn");
        headers.put("xweb_xhr","1");
        headers.put("Content-Type","application/json");
        headers.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11275");
        headers.put("Referer","https://servicewechat.com/wx71702c33334e92bd/13/page-frame.html");
        headers.put("Accept-Encoding","gzip, deflate, br");
        headers.put("Accept-Language","zh-CN,zh;q=0.9");
        headers.put("Accept", "*/*");
        return headers;
    }


    public static void main(String[] args) {
        String url = getUrl();
        log.info(url);
        HttpRequest post = HttpUtil.createPost(url);
        post.addHeaders(headers());
        post.body(body());


//        HttpResponse execute = post.execute();
//        String body = execute.body();
//        log.info(body);


    }
    //appid=2074&clienttype=5&encryptflag=0&pid=2074010&returntype=2&timestamp=1730043870&uuid=wx-ol9sW7RiscrRqWOQ1wPrQSP0NKEM&version=v2
}
